
from django import forms
from django.core.validators import MinValueValidator, MaxValueValidator
from .models import JobIntentionModel
from job.models import AwardModel


class BaseInformationForm(forms.Form):
    name = forms.CharField(max_length=50, label='姓名', error_messages={
        'required': '姓名不能为空',
        'max_length': '姓名不能超过50个字符'
    })
    gender = forms.ChoiceField(
        choices=[('男', '男'), ('女', '女')],
        label='性别',
        error_messages={'required': '请选择性别'}
    )
    birthday = forms.DateField(
        label='出生日期',
        widget=forms.DateInput(attrs={'type': 'date'}),
        error_messages={'required': '出生日期不能为空'}
    )
    phone = forms.CharField(
        max_length=20,
        label='联系电话',
        error_messages={
            'required': '联系电话不能为空',
            'max_length': '联系电话不能超过20个字符'
        }
    )
    email = forms.EmailField(
        label='电子邮箱',
        error_messages={
            'required': '邮箱不能为空',
            'invalid': '请输入有效的邮箱地址'
        }
    )
    location = forms.CharField(
        max_length=100,
        label='所在地区',
        error_messages={
            'required': '所在地区不能为空',
            'max_length': '地区不能超过100个字符'
        }
    )
    personal_description = forms.CharField(
        label='个人描述',
        widget=forms.Textarea(attrs={'rows': 4}),
        required=False  # 允许为空
    )

    def clean_phone(self):
        phone = self.cleaned_data.get('phone')
        if not phone.isdigit():
            raise forms.ValidationError('联系电话必须为数字')
        return phone

class EducationExperienceForm(forms.Form):
    school = forms.CharField(
        max_length=100,
        label='学校名称',
        error_messages={
            'required': '请填写学校名称',
            'max_length': '学校名称不能超过100个字符'
        }
    )

    major = forms.CharField(
        max_length=50,
        label='专业',
        error_messages={
            'required': '请填写专业',
            'max_length': '专业名称不能超过50个字符'
        }
    )

    degree = forms.ChoiceField(
        choices=[
            ('', '请选择'),
            ('专科', '专科'),
            ('本科', '本科'),
            ('硕士', '硕士'),
            ('博士', '博士')
        ],
        label='学历/学位',
        error_messages={'required': '请选择学历/学位'}
    )

    start_date = forms.DateField(
        label='入学时间',
        widget=forms.DateInput(attrs={'type': 'date'}),
        error_messages={'required': '请选择入学时间'}
    )

    end_date = forms.DateField(
        label='毕业时间',
        widget=forms.DateInput(attrs={'type': 'date'}),
        error_messages={'required': '请选择毕业时间'}
    )

    gpa = forms.FloatField(
        label='GPA/平均分',
        required=False,
        validators=[
            MinValueValidator(0, message='GPA不能小于0'),
            MaxValueValidator(4, message='GPA不能大于4')
        ],
        widget=forms.NumberInput(attrs={'step': '0.01'})
    )

    description = forms.CharField(
        label='在校表现',
        widget=forms.Textarea(attrs={'rows': 3}),
        required=False,
        max_length=500,
        error_messages={'max_length': '描述不能超过500个字符'}
    )

class WorkExpericenceForm(forms.Form):
    company = forms.CharField(
        max_length=100,
        label='公司名称',
        error_messages={
            'required': '请填写公司名称',
            'max_length': '公司名称不能超过100个字符'
        }
    )

    position = forms.CharField(
        max_length=50,
        label='职位',
        error_messages={
            'required': '请填写职位',
            'max_length': '职位名称不能超过50个字符'
        }
    )
    department=forms.CharField(
        max_length=50,
        label='部门',
        error_messages={
            'required': '请填写部门',
            'max_length': '部门名称不能超过50个字符'
        }
    )

    start_date = forms.DateField(
        label='入职时间',
        widget=forms.DateInput(attrs={'type': 'date'}),
        error_messages={'required': '请选择入职时间'}
    )

    end_date = forms.DateField(
        label='离职时间',
        widget=forms.DateInput(attrs={'type': 'date'}),
        error_messages={'required': '请选择离职时间'}
    )

    responsibilities = forms.CharField(
        label='工作职责',
        widget=forms.Textarea(attrs={'rows': 3}),
        required=False,
        max_length=500,
        error_messages={'max_length': '描述不能超过500个字符'}
    )


class AwardForm(forms.Form):
    award_name = forms.CharField(
        label='奖项名称',
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'required': 'required'
        })
    )

    award_level = forms.ChoiceField(
        label='获奖级别',
        choices=AwardModel.AWARD_LEVEL_CHOICES,
        widget=forms.Select(attrs={
            'class': 'form-control',
            'required': 'required'
        })
    )

    award_date = forms.DateField(
        label='获奖时间',
        widget=forms.DateInput(attrs={
            'type': 'date',
            'class': 'form-control',
            'required': 'required'
        })
    )

    award_organization = forms.CharField(
        label='颁发机构',
        widget=forms.TextInput(attrs={
            'class': 'form-control',
            'required': 'required'
        })
    )

    award_description = forms.CharField(
        label='奖项描述',
        required=False,
        widget=forms.Textarea(attrs={
            'class': 'form-control',
            'rows': '3'
        })
    )
class SkillForm(forms.Form):
    skill_name=forms.CharField(max_length=200,label='技能名称')
    skill_level=forms.ChoiceField(
        choices=[
            ('了解', '了解'),
            ('熟悉', '熟悉'),
            ('精通', '精通'),
            ('专家', '专家'),
        ],
        label='熟练程度',
        error_messages={'required': '请选择熟练程度'}
    )
    skill_description=forms.CharField(max_length=2000,label='技能描述',required=False)
class ProjectForm(forms.Form):
    project_name=forms.CharField(max_length=200,label='项目名称')
    project_role=forms.CharField(max_length=200,label='担任角色')
    start_date=forms.DateField(label='开始时间',widget=forms.DateInput(attrs={'type':'date'}))
    end_date=forms.DateField(label='结束时间',widget=forms.DateInput(attrs={'type':'date'}),required=False)
    project_description=forms.CharField(max_length=2000,label='项目描述')
    responsibilities=forms.CharField(max_length=2000,label='个人职责')
    technologies=forms.CharField(max_length=2000,label='使用技术',required=False)


class JobIntentionForm(forms.Form):
    expected_position = forms.CharField(
        max_length=100,
        label="期望职位",
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        required=True
    )

    job_nature = forms.ChoiceField(
        choices=JobIntentionModel.JOB_NATURE_CHOICES,
        label="工作性质",
        widget=forms.Select(attrs={'class': 'form-control'}),
        required=True
    )

    expected_location = forms.CharField(
        max_length=100,
        label="期望城市",
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        required=True,
        help_text="可填写多个意向城市，用逗号分隔"
    )

    expected_salary = forms.ChoiceField(
        choices=JobIntentionModel.SALARY_CHOICES,
        label="期望薪资",
        widget=forms.Select(attrs={'class': 'form-control'}),
        required=True
    )

    industry = forms.CharField(
        max_length=100,
        label="期望行业",
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        required=False
    )

    join_time = forms.ChoiceField(
        choices=JobIntentionModel.JOIN_TIME_CHOICES,
        label="可入职时间",
        widget=forms.Select(attrs={'class': 'form-control'}),
        required=True
    )

    job_description = forms.CharField(
        label="补充说明",
        widget=forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
        required=False
    )